package com.hsp.Demo_12_enum;

public class Demo_08 {
    public static void main(String[] args) {
        Person p1 = new Person("张三", new Horse());
        p1.toReiver();
    }
}

class Person{
    private String name;
    private Vehicles vehicles;

    public Person(String name, Vehicles vehicles){
        this.name = name;
        this.vehicles = vehicles;
    }

    public void toReiver(){
        if(!(vehicles instanceof Boat)) {
            vehicles = VehiclesFactory.getBoat();
        }
        vehicles.work();
    }

    public void toCommon(){
        if(!(vehicles instanceof Horse)){
            vehicles = VehiclesFactory.getHorse();
        }
        vehicles.work();
    }
}

interface Vehicles{
    void work();
}

class Horse implements Vehicles{

    @Override
    public void work() {
        System.out.println("我是Horse交通工具！");
    }
}

class Boat implements Vehicles{

    @Override
    public void work() {
        System.out.println("我是Boat交通工具");
    }
}

class VehiclesFactory{

    private static Horse horse = new Horse();

    private VehiclesFactory(){}

    public static Horse getHorse(){
        return  horse;
    }

    public static Boat getBoat(){
        return new Boat();
    }
}